<?php

namespace App\Http\Middleware;

use Closure;

use Nette\Mail\Message;
use Nette\Mail\SmtpMailer;

class EmailMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
          $rs = $next($request);
          //注册后发邮件
          //$request->user()->email;
          if($request->user()) {
              $mail = new Message;

              $mail->setFrom('点点贷官网 <echoiverson@163.com>')
              ->addTo($request->user()->email)
              ->setSubject('邮件测试')
              ->setBody("laravel发邮件很轻松");
              $mailer = new SmtpMailer(array(
              'host' => 'smtp.163.com',
              'username' => 'echoiverson',
              'password' => 'huojian9'
              ));
              $mailer->send($mail);
          }
              return $rs;
      }
}
